package common.validateUser;


import common.CommonResult;
import util.cryptogram.MD5Util;

/**
 * 功能:
 * 作者: 洪世成
 * 日期: 2018/1/19
 * 版权所有: admin
 */
public class ValidateUserUtil {


    public static CommonResult validateUser(String uid, Long timeStamp, String sign, InterfaceUsers interfaceUsers) {


        CommonResult commonResult = new CommonResult();
        Long gap = System.currentTimeMillis() - timeStamp;
        if (3600000 < gap || gap < -3600000) {  //过期
            commonResult.setMessage(commonResult.ZJ007_M);
            commonResult.setCode(commonResult.ZJ007);
            return commonResult;
        }

        String password = interfaceUsers.getPassword(uid);
        if (password == null) {
            commonResult.setMessage(commonResult.ZJ002_M);
            commonResult.setCode(commonResult.ZJ002);
            return commonResult;
        }

        String newSign = MD5Util.md5Hex(timeStamp + password);
        if (newSign.equals(sign)) {
            commonResult.setMessage(commonResult.ZJ001_M);
            commonResult.setCode(commonResult.ZJ001);
        } else {
            commonResult.setMessage(CommonResult.ZJ003_M);
            commonResult.setCode(CommonResult.ZJ003);
        }
        return commonResult;
    }

}
